const Koa = require("koa")
const KoaRouter = require("koa-router")
const KoaBody = require("koa-body")
const KoaStatic = require("koa-static")

const app = new Koa()
const router = new KoaRouter()

let users = [
  { id: 1, name: "zhangsan4000" },
  { id: 2, name: "lisi4000" }
]

app.use(KoaBody())
app.use(KoaStatic("./public"))

app.use(router.routes())

router.get("/users", async ctx => {
  // 获取到函数名称
  const { cb } = ctx.query

  ctx.body = `${cb}(${JSON.stringify(users)})`
})

app.listen(4000)
console.log("run on 4000")
